import os
import datetime
from sqlalchemy import Column, String, create_engine, Integer, DateTime, Boolean, Float
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import relationship

from seed_data import current_path

Base = declarative_base()

db_path = os.path.join(current_path, 'test.db')
my_engine = create_engine('sqlite:///{}?check_same_thread=False'.format(db_path), echo=False)


class BaseDbColumn(object):
    id = Column(Integer, primary_key=True, autoincrement=True)
    created_at = Column(DateTime, nullable=False,
                        default=lambda: datetime.datetime.utcnow())
    updated_at = Column(DateTime, nullable=True,
                        default=lambda: datetime.datetime.utcnow(),
                        onupdate=lambda: datetime.datetime.utcnow())
    deleted_at = Column(DateTime)
    deleted = Column(Boolean, nullable=False, default=False)


class NetworkCfg(Base, BaseDbColumn):
    __tablename__ = 'network_cfg'
    key = Column(String(30))
    bmc = Column(String(30))
    host_name = Column(String(30))
    network_name = Column(String(30))
    ip = Column(String(30))
    mask = Column(String(30))
    default_gateway = Column(String(30))
    gateway = Column(String(30))



class ServerCfg(Base, BaseDbColumn):
    __tablename__ = 'server_cfg'
    key = Column(String(30))
    server_type = Column(String(30))
    bmc = Column(String(30))
    ipmi_user = Column(String(30))
    ipmi_password = Column(String(30))
    ssh_user = Column(String(30))
    ssh_password = Column(String(30))
    status_hardware = Column(String(30))
    status_install = Column(String(30))
    status_raid = Column(String(30))

    # def __repr__(self):
    #     order = {
    #         'order_number': self.order_number,
    #         'buyer': self.buyer,
    #         'product_name': self.product_name,
    #         'product_price': self.product_price,
    #         'product_number': self.product_number
    #     }
    #     return str(order)


Base.metadata.create_all(my_engine, checkfirst=True)
